package com.fireant.ommonadapter.sample;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ListView;

import com.fireant.ommonadapter.CommonAdapter;
import com.fireant.ommonadapter.R;
import com.fireant.ommonadapter.ViewHolder;
import com.fireant.ommonadapter.sample.bean.News;

public class MainActivity extends AppCompatActivity {

    private ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        listView = (ListView) findViewById(R.id.listView);

        CommonAdapter<News> adapter = new CommonAdapter<News>(this, R.layout.list_cell_news) {
            @Override
            public void convert(ViewHolder vh, News data) {
                vh.setText(R.id.tv_title, data.getTitle())
                        .setText(R.id.tv_content, data.getContent());
            }
        };
        listView.setAdapter(adapter);

        adapter.addItem(new News("iOS使用一个MVC替代Brigade’s Experience", "http://www.devtf.cn/"));
        adapter.addItem(new News("React Navtive框架教程", ""));
        adapter.addItem(new News("在Android Lollipop中使用Palette抽取Bitmap颜色", ""));
        adapter.addItem(new News("Android主题动态切换开源库Prism基本原理1-核心功能", ""));
        adapter.addItem(new News("对不起！我来晚了！——《Android群英传》出版祭", ""));
    }
}
